package cn.com.Servlet.SystemGLServlet;

import cn.com.controler.SystemState.SystemStateDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "SystemServlet",value = "/SystemGL")
public class SystemServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String type = request.getParameter("type");
        SystemStateDAO systemStateDAO = new SystemStateDAO();
        if(type.equals("logincheck")){      //查询系统状态
            int state = systemStateDAO.selectState();
            if(state == 1){
                response.getWriter().write("1");
            }else{
                response.getWriter().write("0");
            }
        }else if(type.equals("stop")){      //停用系统
            int endsystem = systemStateDAO.endsystem();
            if(endsystem > 0){
                response.getWriter().write("1");
            }else{
                response.getWriter().write("0");
            }
        }else if(type.equals("start")){      //启用系统
            int endsystem = systemStateDAO.startsystem();
            if(endsystem > 0){
                response.getWriter().write("1");
            }else{
                response.getWriter().write("0");
            }
        }
    }
}
